package com.tensquare.rabbit.listener;

import com.aliyuncs.exceptions.ClientException;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import utils.SmsUtil;

import java.util.Map;

/**
 * Created by WF on 2020/7/25 15:44
 */
@Component
@RabbitListener(queues = "sms")
public class ValidCodeListener {
    @Autowired
    private SmsUtil smsUtil;
    //1.接受验证码消息并给阿里大于发送消息
    @RabbitHandler
    public void getMessage(Map map){
        try {
            //1.1)得到发来的map消息
            String mobile = (String) map.get("mobile");
            String templateCode = (String) map.get("templateCode");
            String signName = (String) map.get("signName");
            String param = (String) map.get("param");
            //1.2)使用阿里大于发送消息
            smsUtil.sendSms(mobile,templateCode,signName,param);
            //提示
            System.out.println("验证码：" + param);
        } catch (ClientException e) {
            e.printStackTrace();
        }

    }
}
